package com.kede.typehanlder;

import com.kede.ienum.FenxiaoStatusEnum;
import com.kede.ienum.FlagEnum;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/***
 ** @Author:Pr.li
 ** @Description:
 ** @Date: create in 2023/5/15 23:05
 ***/
public class FlagEnumTypeHanlder extends BaseTypeHandler<FlagEnum> {
    @Override
    public void setNonNullParameter(PreparedStatement ps, int i, FlagEnum parameter, JdbcType jdbcType) throws SQLException {
        ps.setInt(i,parameter.getEnumIndex());
    }

    @Override
    public FlagEnum getNullableResult(ResultSet rs, String columnName) throws SQLException {
        String code = rs.getString(columnName);
        FlagEnum instance = FlagEnum.parse(columnName);
        return instance;
    }

    @Override
    public FlagEnum getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
        String code = rs.getString(columnIndex);
        FlagEnum instance = FlagEnum.parse(code);
        return instance;
    }

    @Override
    public FlagEnum getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
        return null;
    }
}
